package com.qdlc.p2p.biz.executer.impl;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.executer.BaseExecuter;
import com.qdlc.p2p.common.constant.LogTplNid;
import com.qdlc.p2p.dal.dto.Account;
import com.qdlc.p2p.dal.dto.AccountLog;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.util.SystemConfigs;

/**
 * 处理资金对账，添加资金日志
 *
 * @author ygw
 * @version 2.0
 * @date 2015年11月18日 上午10:37:14
 */
@Service
@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SetTppDifferenceExecuter extends BaseExecuter {

    private String accountLogType = LogTplNid.DIFFERENCE;

    @Override
    public String getAccountLogType() {
        return accountLogType;
    }

	@Override
	public void handleAccountWithLog() {
		accountService.updateAccountByUserId(super.user.getUserId(), super.total, super.useMoney, super.noUseMoney);

		Account account = accountDao.findByUserId(this.user.getUserId());
		AccountLog log = new AccountLog(super.user, accountLogType, new User(SystemConfigs.ADMIN_ID));
		log.setMoney(this.useMoney);
		log.setTotal(account.getTotal());
		log.setUseMoney(account.getUseMoney());
		log.setNoUseMoney(account.getNoUseMoney());
		log.setCollection(account.getCollection());
		log.setRemark(this.getLogRemark());
		accountLogDao.save(log);
	}
}
